package service.impl;

import bean.pojo.GdArticle;
import bean.pojo.GdUserArticlelist;
import dao.GdArticleMapper;
import dao.GdUserArticlelistMapper;
import org.springframework.stereotype.Service;
import service.GdArticleService;

import javax.annotation.Resource;
import java.util.List;


@Service
public class GdArticleServiceImpl implements GdArticleService {

    @Resource
    private GdArticleMapper gdArticlemapper;
    @Resource
    private GdUserArticlelistMapper gdUserArticlelistMapper;

    public int insert(GdArticle pojo){
        return gdArticlemapper.insert(pojo);
    }

    public int insertList(List< GdArticle> pojos){
        return gdArticlemapper.insertList(pojos);
    }

    public List<GdArticle> select(GdArticle pojo){
        return gdArticlemapper.select(pojo);
    }

    /**
     * 通过标签查询文章
     * @param classify
     * @param categoryId
     * @return
     */
    @Override
    public List<GdArticle> selectByCategory(String classify, Long categoryId) {
        return gdArticlemapper.selectByCategory(classify,categoryId);
    }

    @Override
    public boolean updateViewNum(Long articleId) throws Exception{
        return gdArticlemapper.updateViewNum(articleId)>0;
    }

    public int update(GdArticle pojo){
        return gdArticlemapper.update(pojo);
    }

    /**
     * 判断该文章是否已被收藏
     * @param gdUserArticlelist
     * @return
     */
    @Override
    public boolean isFavorite(GdUserArticlelist gdUserArticlelist) {

        return gdUserArticlelistMapper.selectArticlelist(gdUserArticlelist)!=null;
    }

}
